/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.jsf;

import com.controllers.DenominationController;
import com.entities.Denomination;
import java.io.Serializable;
import java.util.logging.Logger;
import javax.ejb.EJB;
import javax.inject.Named;
import javax.enterprise.context.RequestScoped;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedProperty;
import javax.faces.context.FacesContext;

/**
 *
 * @author ben
 */
@Named(value = "denominationAction")
@RequestScoped
public class DenominationAction implements Serializable {

    /**
     * Creates a new instance of DenominationAction
     */
    private static final Logger logger = Logger.getLogger(CompanyDenominationAction.class.getName());
    private Denomination denomination;
    @EJB
    private DenominationController denominationController;
    @ManagedProperty(value = "creditView")
    CreditView creditView;

    public Denomination getDenomination() {
        return denomination;
    }

    public void setDenomination(Denomination denomination) {
        this.denomination = denomination;
    }

    public DenominationAction() {
        this.denomination = new Denomination();
    }

    public String saveDenomination() {
        System.out.println(denomination.getAmount().toString());
        System.out.println(denomination.getCurrency().toString());

        try {
            System.out.println(denominationController.save(denomination));
            System.out.println("Saving Denomination done!");
            FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, "Saving Voucher Successful", "Saving Voucher Successful"));
            logger.info("Saving Voucher Successful");
            setDenomination(new Denomination());
            //creditView.currecyTab(1);
            return null;

        } catch (Exception e) {
            e.printStackTrace();
            FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "Error saving  Voucher ", "Error saving Voucher "));
            logger.warning("Error: Could not save Voucher");
            //creditView.currecyTab(1);
            return "error";

        }
    }

    public DenominationController getDenominationController() {
        return denominationController;
    }

    public void setDenominationController(DenominationController denominationController) {
        this.denominationController = denominationController;
    }

    public CreditView getCreditView() {
        return creditView;
    }

    public void setCreditView(CreditView creditView) {
        this.creditView = creditView;
    }
}
